package com.etc.team2.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.team2.service.StationService;

public class DeleteStationServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		/**
		 * 接收到要被删除的StationId，调用StationService中的deleteStation方法
		 * true,跳转到AllStationServlet
		 * false的页面等春哥做。。。先打印出结果调试就行
		 * error.jsp
		 * */
		String referer=request.getHeader("referer");
		if (referer==null||!referer.startsWith("http://localhost:")) {
			response.sendRedirect("home.jsp");
			return;
		}
		request.setCharacterEncoding("utf-8");
		int stationId=Integer.parseInt(request.getParameter("stationId"));
	    boolean result=	new StationService().deleteStation(stationId);
	    if (result) {
	    	 System.out.println("删除成功");
			request.getRequestDispatcher("AllStationServlet").forward(request, response);
		} else {
            System.out.println("删除失败");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}
